package com.fyy.java8.methodRef;

import org.springframework.http.converter.json.GsonBuilderUtils;

import javax.jws.soap.SOAPBinding;
import java.io.PrintStream;
import java.util.Comparator;
import java.util.function.Consumer;

/**
 * @Author fyy
 * @Description 方法引用
 * @Date 2021/2/25 14:46
 */
public class UserMethodRefTest {

    /** 对象::实例方法 */
    public static void test1(){
        //lambda表达式
        Consumer<User> con1 = user -> System.out.println(user.toString());
        //方法引用
        PrintStream ps = System.out;
        Consumer<User> con2 = ps :: println;
    }

    /** 类::静态方法 */
    public static void test2(){
        //lambda表达式
        Comparator<Integer> com1 = (t1,t2) -> Integer.compare(t1,t2);
        //方法引用
        Comparator<Integer> com2 =  Integer :: compare;
    }

    /** 类::实例方法 */
    public static void test3(){
        //lambda表达式
        Comparator<String> com1 = (t1,t2) -> t1.compareTo(t2);
        //方法引用
        Comparator<String> com2 =  String :: compareTo;
    }

}
